﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace GoldenWOWLauncher.Controls
{
    /// <summary>
    /// Button.xaml 的交互逻辑
    /// </summary>
    public partial class PresentationButton : UserControl
    {
        public PresentationButton()
        {
            InitializeComponent();

            //Hover = new ImageBrush
            //{
            //    ImageSource = new BitmapImage(new Uri("pack://application:,,,/GoldenWOWLauncher;component/Properties/Resources/play_hover.png", UriKind.RelativeOrAbsolute))
            //};

            noHover = new ImageBrush
            {
                //  ImageSource = new BitmapImage(new Uri("pack://application:,,,/GoldenWOWLauncher;component/Properties/../play_hover.png", UriKind.Relative))
                ImageSource = new BitmapImage(new Uri("pack://application:,,,/GoldenWOWLauncher;component/Properties/Resources/play_no_hover.png", UriKind.RelativeOrAbsolute))
            };

            InActive = new ImageBrush
            {
                //ImageSource = new BitmapImage(new Uri("pack://application:,,,/GoldenWOWLauncher;component/Properties/../play_no_active.png", UriKind.Relative))
                ImageSource = new BitmapImage(new Uri("pack://application:,,,/GoldenWOWLauncher;component/Properties/Resources/play_no_active.png", UriKind.RelativeOrAbsolute))
            };

            
            Btn_Core.Click += (s, e) =>
            {
                if (this.IsActive && _clicked != null)
                {
                    _clicked.Invoke(s, e);
                }
            };

        }
        public string Text
        {
            get
            {
                if (Btn_Core.Content != null)
                    return Btn_Core.Content.ToString();
                return string.Empty;
            }
            set { Btn_Core.Content = value; }
        }

        private RoutedEventHandler _clicked;
        public event RoutedEventHandler Clicked
        {
            add
            {
                _clicked += value;
            }

            remove
            {
                if (_clicked != null && value != null)
                    _clicked -= value;
            }
        }

        private ImageBrush noHover;

        //private ImageBrush Hover;

        private ImageBrush InActive;

        private bool _isHover = false;
        private void Button_MouseEnter(object sender, MouseEventArgs e)
        {
            _isHover = true;
            //if (IsActive)
            //    Btn_Core.Background = Hover;
        }

        private void Button_MouseLeave(object sender, MouseEventArgs e)
        {
            _isHover = false;
            //if (IsActive)
            //    Btn_Core.Background = noHover;
        }

        private bool _isActive = false;

        public bool IsActive
        {
            get
            {
                return _isActive;
                //return Btn_Core.IsEnabled;
            }
            set
            {
                _isActive = value;
                Btn_Core.IsEnabled = value;
                if (!_isActive && InActive != null)
                    Btn_Core.Background = InActive;
                /*else if (_isHover && Hover != null)
                    Btn_Core.Background = Hover;*/
                else if (noHover != null)
                    Btn_Core.Background = noHover;
            }
        }

        private void UserControl_Loaded(object sender, RoutedEventArgs e)
        {
         
        }

        //private void UserControl_MouseEnter(object sender, MouseEventArgs e)
        //{
        //    Button_MouseEnter(sender, e);
        //}

        //private void UserControl_MouseLeave(object sender, MouseEventArgs e)
        //{
        //    Button_MouseLeave(sender, e);
        //}
    }
}
